package com.izhaowo.recommend.contrl;

import com.izhaowo.recommend.util.HBaseUtil;
import com.izhaowo.recommend.util.MakeHashRow;
import com.izhaowo.recommend.util.MyUtils;
import com.izhaowo.recommend.vo.*;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.util.*;

/**
 * Created by HASEE on 2019/7/24.
 */
public class Result2Vo {

    private static final Logger logger = LoggerFactory.getLogger(Result2Vo.class);

    /**
     * UserWeddingVO数据转换
     *
     * @param r
     * @return
     */
    public static UserWeddingVO getUserWeddingVO(Result r) {
        UserWeddingVO vo = new UserWeddingVO();
        vo.setUserId(stringCol(r, "user_id"));
        vo.setId(Bytes.toString(r.getRow()));
        vo.setWeddingDate(stringCol(r, "wedding_date"));
        vo.setBrokerId(stringCol(r, "broker_id"));
        vo.setContactsName(stringCol(r, "contacts_name"));
        vo.setContactsMsisdn(stringCol(r, "contacts_msisdn"));
        vo.setContactsAvator(stringCol(r, "contacts_avator"));
        vo.setWeddingMemo(stringCol(r, "memo"));
        vo.setHotel(stringCol(r, "hotel"));
        vo.setBudgetMax(intCol(r, "budget_max"));
        vo.setBudgetMin(intCol(r, "budget_min"));
        vo.setMemo(stringCol(r, "memo"));
        vo.setCtime(stringCol(r, "ctime"));
        vo.setUtime(stringCol(r, "utime"));
        vo.setCompleteTime(stringCol(r, "complete_time"));
        vo.setCityId(stringCol(r, "city_id"));
        vo.setProvinceId(stringCol(r, "province_id"));
        vo.setCityName(stringCol(r, "city_name"));
        vo.setProvinceName(stringCol(r, "province_name"));
        vo.setCode(stringCol(r, "code"));
        vo.setHotelId(stringCol(r, "hotel_id"));
        vo.setHotelAddress(stringCol(r, "hotel_address"));
        vo.setWeddingFlag(intCol(r, "wedding_flag"));
        vo.setArrangeServiceFeePercent(intCol(r, "arrange_service_fee_percent"));
        vo.setIsUse(stringCol(r, "isuse"));
        return vo;
    }

    public static void fillUserWeddingVO(Result r, UserWeddingVO vo) {
        vo.setCityId(stringCol(r, "city_id"));
        vo.setProvinceId(stringCol(r, "province_id"));
        vo.setCityName(stringCol(r, "city_name"));
        vo.setProvinceName(stringCol(r, "province_name"));
    }

    public static String stringCol(Result r, String col) {
        return r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)) == null ? null :
                Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)));
    }

    public static Integer intCol(Result r, String col) {
        byte[] v = r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col));
        if (null != v) {
            String sv = Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)));
            try {
                return Integer.valueOf(sv);
            } catch (Exception e) {
                logger.error(" hbase value change to int error :", e);
            }
        }
        return 0;
//        return r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)) == null ? 0 : (
//                Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col))).length() > 0 ?
//                        Integer.valueOf(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col))))
//                        : 0
//        );
    }

    public static Float floatCol(Result r, String col) {
        byte[] v = r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col));
        if (null != v) {
            String sv = Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)));
            try {
                return Float.valueOf(sv);
            } catch (Exception e) {
                logger.error(" hbase value change to Float error :", e);
            }
        }
//        return 0f;
        return null;
//        return r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)) == null ? 0 : (
//                Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col))).length() > 0 ?
//                        Float.valueOf(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)))) :
//                        0
//        )
//                ;
    }

    public static Double doubleCol(Result r, String col) {
//        return r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)) == null ? 0d : (
//                Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col))).length() > 0 ?
//                        Double.valueOf(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col))))
//                        : 0d);
        byte[] v = r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col));
        if (null != v) {
            String sv = Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes(col)));
            try {
                return Double.valueOf(sv);
            } catch (Exception e) {
                logger.error(" hbase value change to Double error :", e);
            }
        }
        return 0d;
    }

    /**
     * WeddingUserTagVO数据转换
     *
     * @param r
     * @return
     */
    public static WeddingUserTagVO getWeddingUserTagVO(Result r) {
        WeddingUserTagVO vo = new WeddingUserTagVO();
        vo.setId(stringCol(r, "id"));
        vo.setWeddingId(Bytes.toString(r.getRow()));
        vo.setTag1(stringCol(r, "tag1"));
        vo.setTag2(stringCol(r, "tag2"));
        vo.setCtime(stringCol(r, "ctime"));
        vo.setUtime(stringCol(r, "utime"));
        vo.setIsUse(stringCol(r, "isuse"));
        return vo;
    }

    /**
     * HotelVO数据转换
     *
     * @param r
     * @return
     */
    public static HotelVO getHotelVO(Result r) {
        HotelVO vo = new HotelVO();
        vo.setId(Bytes.toString(r.getRow()));
        vo.setAmapId(stringCol(r, "amap_id"));
        vo.setName(stringCol(r, "name"));
        vo.setAddress(stringCol(r, "address"));
        vo.setProvince(stringCol(r, "province"));
        vo.setCity(stringCol(r, "city"));
        vo.setZone(stringCol(r, "zone"));
        vo.setLongitude(stringCol(r, "longitude"));
        vo.setLatitude(stringCol(r, "latitude"));
        return vo;
    }

    public static UserByCrmVO getUserByCrmVO(Result r) {
        UserByCrmVO vo = new UserByCrmVO();
        vo.setId(stringCol(r, "id"));
        vo.setMsisdn(Bytes.toString(r.getRow()));
        vo.setName(stringCol(r, "name"));
        vo.setProvince(stringCol(r, "province"));
        vo.setCity(stringCol(r, "city"));
        vo.setWechat(stringCol(r, "wechat"));
        vo.setWeddingDate(stringCol(r, "wedding_date"));
        vo.setAddress(stringCol(r, "address"));
        vo.setCounselor(stringCol(r, "counselor"));
        vo.setRemark(stringCol(r, "remark"));
        vo.setFirstChannel(stringCol(r, "first_channel"));
        vo.setSecondChannel(stringCol(r, "second_channel"));
        vo.setSecondChannelId(stringCol(r, "second_channel_id"));

        vo.setCrmCenterKey(stringCol(r, "crm_center_key"));
        vo.setBudgetMax(intCol(r, "budget_max"));
        vo.setBudgetMin(intCol(r, "budget_min"));
//        vo.setCrmCenterKey(stringCol(r, "crm_center_key"));
        vo.setIsUse(stringCol(r, "isuse"));
        return vo;
    }

    public static UserByCrmVO getUserByCrmVOV2(Result r) {
        UserByCrmVO vo = new UserByCrmVO();
        vo.setId(stringCol(r, "id"));
        vo.setMsisdn(stringCol(r, "msisdn"));
        vo.setProvince(stringCol(r, "province_id"));
        vo.setWechat(stringCol(r, "wechat"));
        vo.setFirstChannel(stringCol(r, "root_channel_id"));
        vo.setSecondChannelId(stringCol(r, "sub_channel_id"));

        vo.setIsUse(stringCol(r, "is_delete").equals("1") ? "0" : "1");
        return vo;
    }


    public static TalkOrderPlannerVO getTalkOrderPlannerVO(Result r) {
        TalkOrderPlannerVO vo = new TalkOrderPlannerVO();
        vo.setPlanner_id(stringCol(r, "planner_id"));
        vo.setProvince(stringCol(r, "province"));
        vo.setCity(stringCol(r, "city"));
        vo.setSection(intCol(r, "section"));
        vo.setAll_score_final(doubleCol(r, "all_score_final"));
        return vo;
    }


    public static YingjingPlannerSectionVO getYingJingPlannerSectionVO(Result r) {
        YingjingPlannerSectionVO vo = new YingjingPlannerSectionVO();
        vo.setPlanner_id(stringCol(r, "planner_id"));
        vo.setProvince(stringCol(r, "province"));
        vo.setCity(stringCol(r, "city"));
        vo.setSection1(intCol(r, "section1"));
        vo.setSection2(intCol(r, "section2"));
        vo.setSection3(intCol(r, "section3"));
        vo.setSection4(intCol(r, "section4"));
        vo.setSection5(intCol(r, "section5"));
        vo.setSection6(intCol(r, "section6"));
        vo.setDisplay_amount(intCol(r, "display_amount"));
        vo.setUtime(stringCol(r, "utime"));
        return vo;
    }

    public static YingjingPlannerPersonalityVO getYingjingPlannerPersonalityVO(Result r) {
        YingjingPlannerPersonalityVO vo = new YingjingPlannerPersonalityVO();
        vo.setPlanner_id(stringCol(r, "planner_id"));
        vo.setProvince(stringCol(r, "province"));
        vo.setCity(stringCol(r, "city"));
        vo.setPlanner_name(stringCol(r, "planner_name"));

        vo.setAll_budget(intCol(r, "all_budget"));
        vo.setArt(intCol(r, "art"));
        vo.setCareful(intCol(r, "careful"));
        vo.setClam(intCol(r, "clam"));
        vo.setDesign(intCol(r, "design"));
        vo.setFind_difficulty_reason(intCol(r, "find_difficulty_reason"));
        vo.setGentle(intCol(r, "gentle"));

        vo.setGuide_customer(intCol(r, "guide_customer"));
        vo.setHight_budget(intCol(r, "hight_budget"));
        vo.setHight_design_customer(intCol(r, "hight_design_customer"));
        vo.setHumour(intCol(r, "humour"));
        vo.setLow_budget(intCol(r, "low_budget"));
        vo.setOpen(intCol(r, "open"));
        vo.setPhotography_video(intCol(r, "photography_video"));
        vo.setRational(intCol(r, "rational"));
        vo.setSensibility(intCol(r, "sensibility"));
        vo.setSociety(intCol(r, "society"));
        vo.setVolubility(intCol(r, "volubility"));


        vo.setUtime(stringCol(r, "utime"));
        return vo;
    }


//    public static PlannerRecomRankVO getPlannerRecomRankVO(Result r) {
//        PlannerRecomRankVO vo = new PlannerRecomRankVO();
//        String row = Bytes.toString(r.getRow());
//
//        if (row.contains("=")) {
//            vo.setWorkerId(row.split("=")[0]);
//            vo.setFrist(false);
//        } else {
//            vo.setWorkerId(row);
//            vo.setFrist(true);
//        }
//        vo.setCaseRate(doubleCol(r,""));
//        vo.setReorderRate();
//        return vo;
//    }

    /**
     * WorkerVO数据转换
     *
     * @param r
     * @return
     */
    public static WorkerVO getWorkerVO(Result r) {
        WorkerVO vo = new WorkerVO();
        String worker_id = Bytes.toString(r.getRow());
        vo.setId(worker_id);
        vo.setName(stringCol(r, "name"));
        vo.setRealName(stringCol(r, "real_name"));
        vo.setAvator(stringCol(r, "avator"));
        vo.setVocationId(stringCol(r, "vocation_id"));
        vo.setVocation(stringCol(r, "vocation"));
        vo.setHomePage(stringCol(r, "home_page"));
        vo.setSort(intCol(r, "sort"));
        vo.setUserId(stringCol(r, "user_id"));
        vo.setHeight(intCol(r, "height"));
        vo.setWeight(intCol(r, "weight"));
        vo.setSex(intCol(r, "sex"));
        vo.setBirthday(stringCol(r, "birthday"));
        vo.setProfile(stringCol(r, "profile"));
        vo.setDailyLimit(intCol(r, "daily_limit"));
        vo.setStatus(stringCol(r, "status"));
        vo.setCityId((stringCol(r, "city_id")));
        vo.setProvinceId(stringCol(r, "province_id"));
        vo.setCityName(stringCol(r, "city_name"));
        vo.setProvinceName(stringCol(r, "province_name"));
//        List<WorkerServiceCityVO> serviceCity = getWorkerServiceCityVOList(worker_id);
//        vo.setServiceCity(serviceCity);
        vo.setCtime(stringCol(r, "ctime"));
        vo.setAddressId(stringCol(r, "address_id"));
        vo.setAddressName(stringCol(r, "address_name"));
        vo.setIsUse(stringCol(r, "isuse"));
        return vo;
    }


    public static PhotoPlannerVO getPhotoPlannerVO(Result r) {
        PhotoPlannerVO vo = new PhotoPlannerVO();
        vo.setTel(stringCol(r, "tel"));
        vo.setName(stringCol(r, "name"));
        return vo;
    }

    public static WeddingScenePhotoVO getWeddingScenePhotoVO(Result r) {
        WeddingScenePhotoVO vo = new WeddingScenePhotoVO();
        vo.setTel(stringCol(r, "tel"));
        vo.setName(stringCol(r, "name"));
        vo.setId(stringCol(r, "id"));
        vo.setUser_wedding_id(stringCol(r, "user_wedding_id"));
        vo.setCtime(stringCol(r, "ctime"));
        vo.setUpload_worker_id(stringCol(r, "upload_worker_id"));
        return vo;
    }


    public static void fillWorkerVO(Result r, WorkerQueryInfoVO vo) {
        String worker_id = Bytes.toString(r.getRow());
        vo.setId(worker_id);
        vo.setName(stringCol(r, "name"));
        vo.setRealName(stringCol(r, "real_name"));
        vo.setAvator(stringCol(r, "avator"));
        vo.setVocationId(stringCol(r, "vocation_id"));
        vo.setVocation(stringCol(r, "vocation"));
        vo.setHomePage(stringCol(r, "home_page"));
        vo.setSort(intCol(r, "sort"));
        vo.setUserId(stringCol(r, "user_id"));
        vo.setHeight(intCol(r, "height"));
        vo.setWeight(intCol(r, "weight"));
        vo.setSex(intCol(r, "sex"));
        vo.setBirthday(stringCol(r, "birthday"));
        vo.setProfile(stringCol(r, "profile"));
        vo.setDailyLimit(intCol(r, "daily_limit"));
        vo.setStatus(stringCol(r, "status"));
        vo.setCityId((stringCol(r, "city_id")));
        vo.setProvinceId(stringCol(r, "province_id"));
        vo.setCityName(stringCol(r, "city_name"));
        vo.setProvinceName(stringCol(r, "province_name"));
//        List<WorkerServiceCityVO> serviceCity = getWorkerServiceCityVOList(worker_id);
//        vo.setServiceCity(serviceCity);
        vo.setCtime(stringCol(r, "ctime"));
        vo.setAddressId(stringCol(r, "address_id"));
        vo.setAddressName(stringCol(r, "address_name"));
        vo.setIsUse(stringCol(r, "isuse"));
        return;
    }


    public static Map<String, String> getProvinceMap(Result r) {
        Map map = new HashMap<String, String>();
        String id = Bytes.toString(r.getRow());
        map.put(id, stringCol(r, "cn_name"));

        return map;
    }

    public static void getWorkerLocation(Result r, WorkerVO vo) {
        vo.setCityId((stringCol(r, "city_id")));
        vo.setProvinceId(stringCol(r, "province_id"));
        vo.setCityName(stringCol(r, "city_name"));
        vo.setProvinceName(stringCol(r, "province_name"));
        vo.setAddressId(stringCol(r, "address_id"));
        vo.setAddressName(stringCol(r, "address_name"));
    }

    public static void getWorkerInfoLocation(Result r, WorkerQueryInfoVO vo) {
        vo.setCityId((stringCol(r, "city_id")));
        vo.setProvinceId(stringCol(r, "province_id"));
        vo.setCityName(stringCol(r, "city_name"));
        vo.setProvinceName(stringCol(r, "province_name"));
        vo.setAddressId(stringCol(r, "address_id"));
        vo.setAddressName(stringCol(r, "address_name"));
    }


    public static WorkerLocationVO getWorkerLocationVO(Result r) {
        WorkerLocationVO vo = new WorkerLocationVO();
        vo.setWorkerId(Bytes.toString(r.getRow()));
        vo.setCityId((stringCol(r, "city_id")));
        vo.setProvinceId(stringCol(r, "province_id"));
        vo.setCityName(stringCol(r, "city_name"));
        vo.setProvinceName(stringCol(r, "province_name"));
        vo.setAddressId(stringCol(r, "address_id"));
        vo.setAddressName(stringCol(r, "address_name"));

        return vo;
    }


    /**
     * 根据worker_id获取职业人服务城市List
     *
     * @param worker_id
     * @return
     */
    public static List<WorkerServiceCityVO> getWorkerServiceCityVOList(String worker_id) {
        List<WorkerServiceCityVO> serviceCity = new ArrayList<>();
        try {
            ResultScanner scanner = HBaseUtil.queryRowsWithKeys("rp_tb_worker_service_city", worker_id + "=0", worker_id + "=999");
            for (Result result : scanner) {
                String id = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("id")));
                String cityId = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("city_id")));
                String provinceId = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("province_id")));
                String cityName = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("city_name")));
                String provinceName = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("province_name")));
                serviceCity.add(new WorkerServiceCityVO(id, worker_id, cityId, provinceId, cityName, provinceName));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return serviceCity;
    }

    /**
     * UserReserveVO数据转换
     *
     * @param r
     * @return
     */
    public static UserReserveVO getUserReserveVO(Result r) {
        UserReserveVO vo = new UserReserveVO();
        vo.setId(stringCol(r, "id"));
        vo.setUserId(Bytes.toString(r.getRow()));
        vo.setReserveTime(stringCol(r, "reserve_time"));
        vo.setRemark(stringCol(r, "remark"));
        vo.setCtime(stringCol(r, "ctime"));
        vo.setUtime(stringCol(r, "utime"));
        vo.setWorkerId(stringCol(r, "worker_id"));
        vo.setAddress(stringCol(r, "address"));
        return vo;
    }

    public static PlannerRecomRecordVO getPlannerRecomRecordVO(Result r) {
        PlannerRecomRecordVO vo = new PlannerRecomRecordVO();
//        String id;      //rp_tb_planner_recom_record----id"
//        String workerId;    //rp_tb_planner_recom_record----worker_id
//        String weddingId;   //rp_tb_planner_recom_record----rowkey中
//        int ranking;    //rp_tb_planner_recom_record----ranking
//        String ctime;   //rp_tb_planner_recom_record----ctime
//        String utime;   //rp_tb_planner_recom_record----utime
//        String workerName;  //找不到
//        Integer type;   //rp_tb_planner_recom_record----type
//        String crmUserId;   //rp_tb_planner_recom_record----crm_user_id

        vo.setId(stringCol(r, "id"));
        vo.setCtime(stringCol(r, "ctime"));
        vo.setUtime(stringCol(r, "utime"));
        vo.setWorkerId(stringCol(r, "worker_id"));
        vo.setWeddingId(stringCol(r, "wedding_id"));
        vo.setRanking(intCol(r, "ranking"));
        vo.setType(intCol(r, "type"));
        vo.setCrmUserId(stringCol(r, "crm_user_id"));
        return vo;
    }

    /**
     * VocationVO数据转换
     *
     * @param r
     * @return
     */
    public static VocationVO getVocationVO(Result r) {
        VocationVO vo = new VocationVO();
        vo.setName(stringCol(r, "name"));
        vo.setId(Bytes.toString(r.getRow()));
        vo.setCode(stringCol(r, "code"));
        vo.setSort(intCol(r, "sort"));
        return vo;
    }

    /**
     * WorkerScheduleVO数据转换
     *
     * @param r
     * @return
     */
    public static WorkerScheduleVO getWorkerScheduleVO(Result r) {
        WorkerScheduleVO vo = new WorkerScheduleVO();
        vo.setId(Bytes.toString(r.getRow()).split("=")[3]);
        vo.setScheduleDate(Bytes.toString(r.getRow()).split("=")[2].replaceAll("-", "").substring(0, 8));
        vo.setType(intCol(r, "type"));
        vo.setWorkerId(Bytes.toString(r.getRow()).split("=")[0]);
        vo.setIsUse(stringCol(r, "isuse"));
        vo.setFlag(stringCol(r, "flag"));
        vo.setDataType(Bytes.toString(r.getRow()).split("=")[1]);
        return vo;
    }

    public static RecommandResultVO getRecommandResultVO(Result r) {
        RecommandResultVO vo = new RecommandResultVO();
        vo.setWedding_id(stringCol(r, "wedding_id"));
        vo.setInArea(String.valueOf(Bytes.toInt(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("inArea")))));
        vo.setPlannerTag(stringCol(r, "plannerTag"));
        vo.setRecom(stringCol(r, "recom"));
        vo.setStartTime(stringCol(r, "startTime"));
        vo.setProvince(stringCol(r, "province"));
        vo.setProvinceId(stringCol(r, "provinceId"));
        vo.setBudgetMax(String.valueOf(Bytes.toInt(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("budgetMax")))));
        vo.setCityId(stringCol(r, "cityId"));
        vo.setCityName(stringCol(r, "cityName"));
        vo.setHotel(stringCol(r, "hotel"));
        vo.setHotelId(stringCol(r, "hotelId"));
        vo.setWeddingDate(stringCol(r, "weddingDate"));

        return vo;
    }


    public static HotelInAreaMsgVO getHotelInAreaMsgVO(Result r) {
        HotelInAreaMsgVO vo = new HotelInAreaMsgVO();
        vo.setDayStr(stringCol(r, "dayStr"));
        vo.setFake_worker_count(stringCol(r, "fake_worker_count"));
        vo.setHotel_id(stringCol(r, "hotel_id"));
        vo.setHotel_name_f1(stringCol(r, "hotel_name_f1"));
        vo.setInArea(stringCol(r, "inArea"));
        vo.setMin_dis(stringCol(r, "min_dis"));
        vo.setTruth_worker_count(stringCol(r, "truth_worker_count"));


        return vo;
    }

    /**
     * UserVO数据转换
     *
     * @param r
     * @return
     */
    public static UserVO getUserVO(Result r) {
        UserVO vo = new UserVO();
        vo.setId(Bytes.toString(r.getRow()));
        vo.setName(stringCol(r, "name"));
        vo.setAvator(stringCol(r, "avator"));
        vo.setMsisdn(stringCol(r, "msisdn"));
        vo.setType(intCol(r, "type"));
        vo.setMark(intCol(r, "mark"));
        vo.setIsUse(stringCol(r, "isuse"));
        return vo;
    }

    public static PlannerRecomRankVO getPlannerRecomRankVO(Result r) {
        PlannerRecomRankVO vo = new PlannerRecomRankVO();
        String row = Bytes.toString(r.getRow());
        if (row.contains("=")) {
            vo.setWorkerId(row.split("=")[0]);
            vo.setFrist(false);
        } else {
            vo.setWorkerId(row);
            vo.setFrist(true);
        }
        vo.setCaseRate(doubleCol(r, "case_ratee"));
        vo.setReorderRate(doubleCol(r, "reorder_rate"));
        vo.setPreSpeScore(doubleCol(r, "preSpeScore"));
        vo.setAllScoreFinal(doubleCol(r, "all_score_final"));
        vo.setSot(doubleCol(r, "sot"));
        vo.setScoreFlag1(intCol(r, "all_score_final_flag1"));
        vo.setScoreFlag2(intCol(r, "all_score_final_flag2"));
        vo.setScoreFlag3(intCol(r, "all_score_final_flag3"));
        vo.setScoreFlag4(intCol(r, "all_score_final_flag4"));
        vo.setScoreFlag5(intCol(r, "all_score_final_flag5"));
        vo.setScoreFlag6(doubleCol(r, "b5_55"));
        vo.setScoreFlag7(doubleCol(r, "b55_65"));
        vo.setScoreFlag8(doubleCol(r, "b65_75"));
        vo.setScoreFlag9(doubleCol(r, "b75_9"));
        vo.setScoreFlag10(doubleCol(r, "b9_10"));
        vo.setScoreFlag11(doubleCol(r, "b10_13"));
        vo.setScoreFlag12(doubleCol(r, "b13_20"));
        vo.setScoreFlag13(doubleCol(r, "b20_90"));
        vo.setProvince(stringCol(r, "location_prov"));
        vo.setType(stringCol(r, "ttype"));
        vo.setVersion("v1");

        return vo;
    }

    public static PlannerRecomRankVO getPlannerRecomRankVOVersion2(Result r) {
        PlannerRecomRankVO vo = new PlannerRecomRankVO();
        vo.setWorkerId(stringCol(r, "worker_id"));
        vo.setSection(stringCol(r, "section"));
        vo.setCaseRate(doubleCol(r, "case_rate"));
        vo.setReorderRate(doubleCol(r, "reorder_rate"));
        vo.setPreSpeScore(doubleCol(r, "preSpeScore"));
        vo.setAllScoreFinal(doubleCol(r, "all_score_final"));
        vo.setSot(doubleCol(r, "sort"));
        vo.setScoreFlag1(intCol(r, "all_score_final_flag1"));
        vo.setScoreFlag2(intCol(r, "all_score_final_flag2"));
        vo.setScoreFlag3(intCol(r, "all_score_final_flag3"));
        vo.setScoreFlag4(intCol(r, "all_score_final_flag4"));
        vo.setScoreFlag5(intCol(r, "all_score_final_flag5"));
        vo.setScoreFlag6(doubleCol(r, "b5_55"));
        vo.setScoreFlag7(doubleCol(r, "b55_65"));
        vo.setScoreFlag8(doubleCol(r, "b65_75"));
        vo.setScoreFlag9(doubleCol(r, "b75_9"));
        vo.setScoreFlag10(doubleCol(r, "b9_10"));
        vo.setScoreFlag11(doubleCol(r, "b10_13"));
        vo.setScoreFlag12(doubleCol(r, "b13_20"));
        vo.setScoreFlag13(doubleCol(r, "b20_90"));
        vo.setProvince(stringCol(r, "province"));
        vo.setVersion("v2");

        return vo;
    }


    public static PlannerRecomRankVO getPlannerRecomRankVOJJ(Result r) {
        PlannerRecomRankVO vo = new PlannerRecomRankVO();
        vo.setWorkerId(stringCol(r, "worker_id"));
        vo.setSection(stringCol(r, "section"));
        vo.setCaseRate(doubleCol(r, "案例率"));
        vo.setReorderRate(doubleCol(r, "reorder_rate"));
        vo.setPreSpeScore(doubleCol(r, "preSpeScore"));
        vo.setAllScoreFinal(doubleCol(r, "尾款前整体打分"));
        vo.setSot(doubleCol(r, "sort"));
        vo.setScoreFlag1(intCol(r, "all_score_final_flag1"));
        vo.setScoreFlag2(intCol(r, "all_score_final_flag2"));
        vo.setScoreFlag3(intCol(r, "all_score_final_flag3"));
        vo.setScoreFlag4(intCol(r, "all_score_final_flag4"));
        vo.setScoreFlag5(intCol(r, "all_score_final_flag5"));
        vo.setScoreFlag6(doubleCol(r, "b5_55"));
        vo.setScoreFlag7(doubleCol(r, "b55_65"));
        vo.setScoreFlag8(doubleCol(r, "b65_75"));
        vo.setScoreFlag9(doubleCol(r, "b75_9"));
        vo.setScoreFlag10(doubleCol(r, "b9_10"));
        vo.setScoreFlag11(doubleCol(r, "b10_13"));
        vo.setScoreFlag12(doubleCol(r, "b13_20"));
        vo.setScoreFlag13(doubleCol(r, "b20_90"));
        vo.setProvince(stringCol(r, "province"));
        vo.setVersion("v3");

        return vo;
    }

    public static JJPlannerVO getJJPlanner(Result r) {
        JJPlannerVO vo = new JJPlannerVO();
        vo.setWorker_id(stringCol(r, "worker_id"));
        vo.setBeforeEndAllScore(doubleCol(r, "尾款前整体打分"));
        vo.setCasePoint(doubleCol(r, "方案点"));
        vo.setCaseRadio(doubleCol(r, "案例率"));
        vo.setCommuintLevel(doubleCol(r, "沟通水平"));
        vo.setDesionScore(doubleCol(r, "设计感得分"));
        vo.setExecuteWeddingCount(doubleCol(r, "方案点"));
        vo.setRegionUpWeddingCount(doubleCol(r, "区间上传婚礼数"));
        vo.setSection(stringCol(r, "section"));
        vo.setSort(doubleCol(r, "sort"));
        vo.setWordsCommentRadio(doubleCol(r, "文字评价率"));
        vo.setProvince(stringCol(r, "province"));
        vo.setJJArea(stringCol(r, "jj_area"));
        vo.setJJCode(stringCol(r, "jj_code"));

        return vo;
    }


    public static Map<String, List<String>> getPlannerWeddingTag(Result r) {
        Map<String, List<String>> workerTags = new HashMap<>();
        String worker_id = stringCol(r, "worker_id");
        List tags = new ArrayList<String>();
        Map<byte[], byte[]> familyMap = r.getFamilyMap(Bytes.toBytes("info"));
        for (Map.Entry<byte[], byte[]> entry : familyMap.entrySet()) {
            if ("1".equals(Bytes.toString(entry.getValue())))
                tags.add(Bytes.toString(entry.getKey()));
        }
        workerTags.put(worker_id, tags);
        return workerTags;
    }


    public static PlannerRecomRankVO getHighPlannerRecomRankVO(Result r) {
        PlannerRecomRankVO vo = new PlannerRecomRankVO();
        String row = Bytes.toString(r.getRow());
        if (row.contains("=")) {
            vo.setWorkerId(row.split("=")[0]);
            vo.setFrist(false);
        } else {
            vo.setWorkerId(row);
            vo.setFrist(true);
        }
        vo.setCaseRate(doubleCol(r, "case_rate"));
        vo.setReorderRate(doubleCol(r, "reorder_rate"));
        vo.setPreSpeScore(doubleCol(r, "preSpeScore"));
        vo.setAllScoreFinal(doubleCol(r, "all_score_final"));
        vo.setSot(doubleCol(r, "sot"));
        vo.setScoreFlag1(intCol(r, "all_score_final_flag1"));
        vo.setScoreFlag2(intCol(r, "all_score_final_flag2"));
        vo.setScoreFlag3(intCol(r, "all_score_final_flag3"));
        vo.setScoreFlag4(intCol(r, "all_score_final_flag4"));
        vo.setScoreFlag5(intCol(r, "all_score_final_flag5"));
        vo.setHighScoreFlag6(intCol(r, "all_score_final_flag6"));
        vo.setScoreFlag6(doubleCol(r, "b5_55"));
        vo.setScoreFlag7(doubleCol(r, "b55_65"));
        vo.setScoreFlag8(doubleCol(r, "b65_75"));
        vo.setScoreFlag9(doubleCol(r, "b75_9"));
        vo.setScoreFlag10(doubleCol(r, "b9_10"));
        vo.setScoreFlag11(doubleCol(r, "b10_13"));
        vo.setScoreFlag12(doubleCol(r, "b13_20"));
        vo.setScoreFlag13(doubleCol(r, "b20_90"));
        vo.setProvince(stringCol(r, "省"));
        vo.setType(stringCol(r, "type"));
        vo.setVersion("v1");

        return vo;
    }

    /**
     * WorkerServiceVO数据转换
     *
     * @param r
     * @return
     */
    public static List<WorkerServiceVO> getWorkerServiceVO(Result r) {
        WorkerServiceVO vo = new WorkerServiceVO();
        vo.setId(stringCol(r, "id"));
        String row = Bytes.toString(r.getRow());
        if (row.contains("=") && row.split("=").length > 2) {
            String[] rows = row.split("=");
            vo.setWorkerId(rows[0]);
            vo.setServiceId(rows[2]);
            // 2019.08.08 : 增加tb_service数据。
            ServiceVO serviceVo = getServiceVO(rows[2]);
            vo.setServiceName(serviceVo.getName());
            vo.setMemo(serviceVo.getMemo());
            vo.setPeople(serviceVo.getPeople());
            vo.setType(serviceVo.getType());
        }
        vo.setMemo(stringCol(r, "memo"));
        vo.setDisplayAmount(intCol(r, "display_amount"));
        vo.setSettlementAmount(intCol(r, "settlement_amount"));
        vo.setStatus(intCol(r, "status"));
        vo.setIsUse(stringCol(r, "isuse"));

        return transWorkerService(vo);
        // 2019.08.08 : 下面的字段没有在tb_worker_service表内。
//        vo.setServiceName(stringCol(r, "name"));
//        vo.setMemo(stringCol(r, "smemo"));
//        vo.setPeople(intCol(r, "people"));
//        vo.setType(intCol(r, "wtype"));
//        vo.setActivityAmount(intCol(r, "activity_amount"));
    }


    /**
     * WorkerServiceVO数据转换
     *
     * @param r
     * @return
     */
    public static WorkerServiceVO getOneWorkerServiceVO(Result r) {
        WorkerServiceVO vo = new WorkerServiceVO();
        vo.setId(stringCol(r, "id"));
        String row = Bytes.toString(r.getRow());
        if (row.contains("=") && row.split("=").length > 2) {
            String[] rows = row.split("=");
            vo.setWorkerId(rows[0]);
            vo.setServiceId(rows[2]);
            // 2019.08.08 : 增加tb_service数据。
            ServiceVO serviceVo = getServiceVO(rows[2]);
            vo.setServiceName(serviceVo.getName());
            vo.setMemo(serviceVo.getMemo());
            vo.setPeople(serviceVo.getPeople());
            vo.setType(serviceVo.getType());
        }
        vo.setMemo(stringCol(r, "memo"));
        vo.setDisplayAmount(intCol(r, "display_amount"));
        vo.setSettlementAmount(intCol(r, "settlement_amount"));
        vo.setStatus(intCol(r, "status"));
        vo.setIsUse(stringCol(r, "isuse"));

        return vo;
        // 2019.08.08 : 下面的字段没有在tb_worker_service表内。
//        vo.setServiceName(stringCol(r, "name"));
//        vo.setMemo(stringCol(r, "smemo"));
//        vo.setPeople(intCol(r, "people"));
//        vo.setType(intCol(r, "wtype"));
//        vo.setActivityAmount(intCol(r, "activity_amount"));
    }


    /**
     * 2019.08.08 添加方法，通过service_id获取tb_service表数据
     */
    public static ServiceVO getServiceVO(String service_id) {
        ServiceVO vo = new ServiceVO();
        Result r = HBaseUtil.getRow("v2_rp_tb_service", service_id);
        vo.setServiceId(service_id);
        vo.setName(stringCol(r, "name"));
        vo.setVocationId(stringCol(r, "vocation_id"));
        vo.setMemo(stringCol(r, "memo"));
        vo.setStatus(stringCol(r, "status"));
        vo.setPeople(intCol(r, "people"));
        vo.setType(intCol(r, "type"));
        return vo;
    }

    public static ServiceVO getServiceVOFromR(Result r) {
        ServiceVO vo = new ServiceVO();
        vo.setServiceId(Bytes.toString(r.getRow()));
        vo.setName(stringCol(r, "name"));
        vo.setVocationId(stringCol(r, "vocation_id"));
        vo.setMemo(stringCol(r, "memo"));
        vo.setStatus(stringCol(r, "status"));
        vo.setPeople(intCol(r, "people"));
        vo.setType(intCol(r, "type"));
        return vo;
    }


    /**
     * 2019.08.08 添加方法，通过service_id获取tb_service表数据
     */
    public static List<WorkerServiceVO> transWorkerService(WorkerServiceVO vo) {
        ResultScanner rs = HBaseUtil.queryRowsWithKeys("v2_rp_tb_worker_activity", vo.getWorkerId() + "=", vo.getWorkerId() + ">");
        Iterator<Result> it = rs.iterator();
        List<WorkerServiceVO> list = new ArrayList<>();
        while (it.hasNext()) {
            WorkerServiceVO temp = new WorkerServiceVO();
            BeanUtils.copyProperties(vo, temp);
            WorkerActivityVO innerVo = getWorkerActivityVO(it.next());
            if ("0".equals(innerVo.getStatus()) && innerVo.getAttach_id().equals(vo.getId())) {
                temp.setActivityAmount(innerVo.getActivity_amount());
                list.add(temp);
            }
        }

        if (list.isEmpty()) list.add(vo);
        return list;
    }

    public static WorkerActivityVO getWorkerActivityVO(Result r) {
        WorkerActivityVO vo = new WorkerActivityVO();
        vo.setId(stringCol(r, "worker_id"));
        vo.setActivity_id(stringCol(r, "activity_id"));
        vo.setStatus(stringCol(r, "status"));
        vo.setType(intCol(r, "type"));
        vo.setActivity_amount(intCol(r, "activity_amount"));
        vo.setAttach_id(stringCol(r, "attach_id"));

        return vo;
    }


    /**
     * WorkerWeddingOrderVO数据转换
     *
     * @param r
     * @return
     */
    public static WorkerWeddingOrderVO getWorkerWeddingOrderVO(Result r) {
        // worker_id=1/2=ctime/schedule_date=wedding_id
        WorkerWeddingOrderVO vo = new WorkerWeddingOrderVO();
        vo.setId(stringCol(r, "id"));
        vo.setOrderId(stringCol(r, "order_id"));
        vo.setCode(stringCol(r, "code"));
        vo.setUserId(stringCol(r, "user_id"));
        String row = Bytes.toString(r.getRow());
        if (row.contains("=") && row.split("=").length > 3) {
            vo.setWorkerId(Bytes.toString(r.getRow()).split("=")[0]);
            vo.setWeddingId(Bytes.toString(r.getRow()).split("=")[3]);
        }

        vo.setBrokerId(stringCol(r, "broker_id"));
        vo.setScheduleId(stringCol(r, "schedule_id"));
        vo.setWeddingDate(stringCol(r, "wedding_date"));
        vo.setWeddingOrderStatus(stringCol(r, "status"));
        vo.setDisplayAmount(intCol(r, "display_amount"));
        vo.setSettlementAmount(intCol(r, "settlement_amount"));
        vo.setServiceName(stringCol(r, "name"));
        vo.setServiceMemo(stringCol(r, "smemo"));
        vo.setPeople(intCol(r, "people"));
        vo.setCtime(stringCol(r, "ctime"));
        vo.setCompletedTime(stringCol(r, "complete_time"));
        vo.setCancelTime(stringCol(r, "cancel_time"));
        vo.setRemoteFee(intCol(r, "remote_fee"));
        vo.setIsUse(stringCol(r, "isuse"));
        vo.setFlag(stringCol(r, "flag"));
        return vo;
    }

    /**
     * UserWeddingTeamMemberVO数据转换
     *
     * @param r
     * @return
     */
    public static UserWeddingTeamMemberVO getUserWeddingTeamMemberVO(Result r) {
        //wedding_id=wedding_date=id
        UserWeddingTeamMemberVO vo = new UserWeddingTeamMemberVO();
        vo.setId(Bytes.toString(r.getRow()).split("=")[2]);
        vo.setUserWeddingTeamId(stringCol(r, "user_wedding_team_id"));
        vo.setWeddingWorkerId(stringCol(r, "wedding_worker_id"));
        vo.setWeddingId(Bytes.toString(r.getRow()).split("=")[0]);
        vo.setName(stringCol(r, "name"));
        vo.setAvator(stringCol(r, "avator"));
        vo.setHomePage(stringCol(r, "home_page"));
        vo.setVocation(stringCol(r, "vocation"));
        vo.setMsisdn(stringCol(r, "msisdn"));
        vo.setServiceName(stringCol(r, "service_name"));
        vo.setWorkerServiceId(stringCol(r, "worker_service_id"));
        vo.setDisplayAmount(intCol(r, "display_amount"));
        vo.setSettlementAmount(intCol(r, "settlement_amount"));
        vo.setWeddate(Bytes.toString(r.getRow()).split("=")[1]);
        vo.setCtime(stringCol(r, "ctime"));
        vo.setUtime(stringCol(r, "utime"));
        vo.setPeople(intCol(r, "people"));
        vo.setBaseDisplayAmount(intCol(r, "base_display_amount"));
        vo.setBaseSettlementAmount(intCol(r, "base_settlement_amount"));
        vo.setPriceRiseId(stringCol(r, "price_rise_id"));
        vo.setServiceId(stringCol(r, "service_id"));
        vo.setRecomNum(intCol(r, "recom_num"));
        vo.setSot(doubleCol(r, "sot"));
        vo.setIsUse(stringCol(r, "isuse"));
        return vo;
    }


    /**
     * WorkerMonthOrderLimitVO数据转换
     *
     * @param r
     * @return
     */
    public static WorkerMonthOrderLimitVO getWorkerMonthOrderLimitVO(Result r) {
        if ("0".equals(stringCol(r, "isuse"))) return null;
        // worker_id=year=month
        WorkerMonthOrderLimitVO vo = new WorkerMonthOrderLimitVO();
        vo.setId(stringCol(r, "id"));
        vo.setWorkerId(Bytes.toString(r.getRow()).split("=")[0]);
        vo.setLimitNum(intCol(r, "limit_num"));
        vo.setYear(Bytes.toString(r.getRow()).split("=")[1]);
        vo.setMonth(Bytes.toString(r.getRow()).split("=")[2]);
        vo.setReceiptNum(intCol(r, "receipt_num"));
        vo.setIsUse(stringCol(r, "isuse"));
        return vo;
    }

    /**
     * PointDistanceVO数据转换
     *
     * @param r
     * @return
     */
    public static PointDistanceVO getPointDistanceVO(Result r) {
        PointDistanceVO vo = new PointDistanceVO();
        vo.setDistance(floatCol(r, "distance"));
        String h_jwd = stringCol(r, "h_jwd");
        vo.setOriginsLatitude((h_jwd != null && h_jwd.length() > 0) ? h_jwd.split(",")[0] : null);
        vo.setOriginsLongitude((h_jwd != null && h_jwd.length() > 0) ? h_jwd.split(",")[1] : null);
        String p_jwd = stringCol(r, "p_jwd");
        vo.setDestinationLatitude((p_jwd != null && p_jwd.length() > 0) ? p_jwd.split(",")[0] : null);
        vo.setDestinationLongitude((p_jwd != null && p_jwd.length() > 0) ? p_jwd.split(",")[1] : null);
//
//        String[] hotel_jwdArr = Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("h_jwd"))).split(",");
//        String[] worker_jwdArr = Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("p_jwd"))).split(",");
//        vo.setOriginsLatitude(worker_jwdArr[0]);
//        vo.setOriginsLongitude(worker_jwdArr[1]);
//        vo.setDestinationLatitude(hotel_jwdArr[0]);
//        vo.setDestinationLongitude(hotel_jwdArr[1]);
        return vo;
    }

    /**
     * HotelPlannerRecomRankVO数据转换
     *
     * @param r
     * @return
     */
    public static HotelPlannerRecomRankVO getHotelPlannerRecomRankVO(Result r) {
        HotelPlannerRecomRankVO vo = new HotelPlannerRecomRankVO();
//        vo.setCtime(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("ctime"))));
//        vo.setWorkerId(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("worker_id"))));
//        vo.setProvinceName(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("province"))));
//        vo.setCityName(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("city"))));
//        vo.setZone(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("zone"))));
//        vo.setHotel(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("hotel"))));
//        vo.setSection(Bytes.toInt(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("section"))));
//        vo.setSot(Bytes.toFloat(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("sot"))));
//        vo.setCtime(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("ctime"))));
//        vo.setAmapId(Bytes.toString(r.getValue(Bytes.toBytes("info"), Bytes.toBytes("ctime"))));

        vo.setCtime(stringCol(r, "ctime"));
        vo.setWorkerId(stringCol(r, "worker_id"));
        String province = stringCol(r, "province");
        String city = stringCol(r, "city");
        String zone = stringCol(r, "zone");
        Float sort = floatCol(r, "sort");
        Float sot = floatCol(r, "sot");
        vo.setProvinceName(null == province || "".equals(province) ? stringCol(r, "h_province") : province);
        vo.setCityName(null == city || "".equals(city) ? stringCol(r, "h_city") : city);
        vo.setZone(null == zone || "".equals(zone) ? stringCol(r, "h_area") : zone);
        vo.setHotel(stringCol(r, "hotel"));
        vo.setSection(intCol(r, "section"));
        vo.setSot(null == sort ? (null == sot ? 0 : sot) : sort);
        vo.setBaseSot(null == sot ? 0 : sot);
        Float distance = floatCol(r, "distance");
        vo.setDistance(null == distance ? 0 : distance);
        return vo;
    }

//    public static HotelPlannerRecomRankVO getHotelPlannerAreaScoreVO(Result r) {
//        HotelPlannerRecomRankVO vo = new HotelPlannerRecomRankVO();
//        vo.setCtime(stringCol(r, "ctime"));
//        vo.setWorkerId(stringCol(r, "worker_id"));
//        vo.setProvinceName(stringCol(r, "h_province"));
//        vo.setCityName(stringCol(r, "h_city"));
//        vo.setZone(stringCol(r, "h_area"));
//        vo.setHotel(stringCol(r, "hotel"));
//        vo.setSection(intCol(r, "section"));
//        vo.setSot(floatCol(r, "sort"));
//        vo.setBaseSot(floatCol(r, "sot"));
//        vo.setDistance(floatCol(r, "distance"));
//        return vo;
//    }

    /**
     * 通过酒店、预算，获取推荐策划师列表
     *
     * @return
     */
    public static List<HotelPlannerRecomRankVO> getPlannerRecList(String time, int totalBudget, String hotelId,
                                                                  int distance, String hotelName, String amountInterval) {
        List<HotelPlannerRecomRankVO> list = new ArrayList<>();
        try {
            List<String> budgetCandoPlannerList = getBudgetCandoPlannerList(totalBudget); // 获取预算合适的List。
            List<String> timeCandoPlannerList = getTimeCandoPlannerList(time, budgetCandoPlannerList);// 获取档期合适的List。
            List<String> distanceCandoPlannerList = getDistanceCandoPlannerList(hotelId, distance, timeCandoPlannerList); // 获取距离合适的List。
            List<String> lastPlannerList = getHadDoPlannerList(hotelId, hotelName, amountInterval, distanceCandoPlannerList);// 在指定酒店做过指定预算的List
            // 当里面包含了策划师信息的时候，再进行组装。
//            if (lastPlannerList.size() > 0) {
//                for (String planner_id : lastPlannerList) {
//                    String[] arr = getHotelInfo(hotelId);
//                    list.add(new PlannerRecResultVO(planner_id, arr[0], arr[1], arr[2], hotelName, 0f, Integer.parseInt(amountInterval), 0, 0));
//                }
//            } else {
//                if (distanceCandoPlannerList.size() > 0) {
//                    for (String planner_id : distanceCandoPlannerList) {
//                        String[] arr = getHotelInfo(hotelId);
//                        list.add(new PlannerRecResultVO(planner_id, arr[0], arr[1], arr[2], hotelName, 0f, Integer.parseInt(amountInterval), 0, 0));
//                    }
//                } else {
//                    lastPlannerList = getDistanceCandoPlannerList(hotelId, distance * 2, timeCandoPlannerList); // 获取距离合适的List。
//                }
//            }

            /**
             * 逻辑判断：如果最终list里面有东西，不进行处理；
             *         如果最终list里面没有东西，则最终list等于距离list；
             */
            if (lastPlannerList.size() < 1) {
                if (distanceCandoPlannerList.size() >= 1) {
                    lastPlannerList = distanceCandoPlannerList;
                } else {
                    lastPlannerList = getDistanceCandoPlannerList(hotelId, distance * 2, timeCandoPlannerList);
                }
            }

            /**
             * 逻辑判断：
             */
            List<String> endList;
            if (lastPlannerList.size() > 3) {   // 对lastPlannerList进行排序
                endList = MyUtils.sortListAndTopN(lastPlannerList, 3);
            } else {
                endList = MyUtils.sortList(lastPlannerList);
            }
            for (String planner_id : endList) {
                String[] arr = getHotelInfo(hotelId);
                HotelPlannerRecomRankVO vo = new HotelPlannerRecomRankVO();
                vo.setWorkerId(planner_id);
                vo.setProvinceName(arr[0]);
                vo.setCityName(arr[1]);
                vo.setZone(arr[2]);
                vo.setHotel(hotelName);
                vo.setSot(0f);
                vo.setSection(Integer.parseInt(amountInterval));
                list.add(vo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 返回预算合适的策划师List
     *
     * @return
     */
    public static List<String> getBudgetCandoPlannerList(int totalBudget) {
        List<String> list = new ArrayList<>();
        // 1.获取所有策划师id
        ResultScanner scanner = HBaseUtil.getScanner("worker_service_info");
        for (Result result : scanner) {
            String flag = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("flag")));
            if (flag.equals("0")) {
                // 2.通过服务费对比0.1*总预算，添加策划师list
                String service_amount = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("service_amount")));
                String planner_id = Bytes.toString(result.getRow()).split("::")[0];
                if (service_amount != null) {
                    Double s_amount = Double.valueOf(service_amount);
                    // 3.限定条件:预算合法&&已写入不再写
                    if (s_amount <= ((double) totalBudget / 10d) && !list.contains(planner_id)) {
                        list.add(planner_id);
                    }
                }
            }
        }
        // 4.返回合适的策划师list
        return list;
    }

    /**
     * 返回档期合适的策划师List
     *
     * @return
     */
    public static List<String> getTimeCandoPlannerList(String time, List<String> budgetCandoPlannerList) {
        List<String> list = new ArrayList<>();
        // 1.首先针对daily_limit=0的进行过滤。
        Map<String, Integer> limitMap = new HashMap<>();
        for (String planner_id : budgetCandoPlannerList) {
            String limit = HBaseUtil.getValue("tb_worker", planner_id, "info", "daily_limit");
            if (limit != null) {
                int day_limit = Integer.parseInt(limit);
                if (day_limit > 0) {
                    limitMap.put(planner_id, day_limit);
                }
            }
        }
        // 2.针对type=1/2的进行过滤。
        Map<String, Integer> zerosMap = new HashMap<>();
        ResultScanner scheduleScanner = HBaseUtil.getScanner("tb_worker_schedule");
        for (Result result : scheduleScanner) {
            String schedule_date = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("schedule_date")));
            if (schedule_date != null && schedule_date.equals(time)) {
                String worker_id = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("worker_id")));
                if (limitMap.keySet().contains(worker_id)) {
                    String type = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("type")));
                    if (type.equals("1") || type.equals("2")) {
                        limitMap.remove(worker_id);
                    } else if (type.equals("0")) {
                        //@TODO 逻辑没有问题 么， 1、limitMap 已经从  worker_service_info 查询，是不是多余 2、不在 limitMap里面的worker_id  加入 值一直为1
                        if (zerosMap.keySet().contains(worker_id) && limitMap.keySet().contains(worker_id) && workerIsPlanner(worker_id)) {
                            zerosMap.put(worker_id, zerosMap.get(worker_id) + 1);
                        } else {
                            zerosMap.put(worker_id, 1);
                        }
                    }
                }
            }
        }
        // 3.针对type=0的，但次数小于limit的进行过滤。
        for (String planner_id : zerosMap.keySet()) {
            if (limitMap.keySet().contains(planner_id)) {
                if (zerosMap.get(planner_id) >= limitMap.get(planner_id)) {
                    limitMap.remove(planner_id);
                }
            }
        }
        for (String planner_id : limitMap.keySet()) {
            list.add(planner_id);
        }
        return list; // 返回档期List。
    }

    /**
     * 获取距离合适的策划师List
     *
     * @return
     */
    public static List<String> getDistanceCandoPlannerList(String hotelId, int distance, List<String> timeCandoPlannerList) {
        List<String> list = new ArrayList<>();
        // 1.根据已获得策划师，查询酒店到策划师距离
        for (String planner : timeCandoPlannerList) {
            String row = String.valueOf(MakeHashRow.hashCode(hotelId + ":" + planner));
            String dis = HBaseUtil.getValue("workers_hotel_distance", row, "info", "distance");
            // 2.进行数据判断
            if (dis != null) {
                if (Integer.valueOf(dis) <= distance && !list.contains(planner)) {
                    list.add(planner);
                }
            }
        }
        // 3.返回合适策划师List
        return list;
    }

    /**
     * 获取在指定酒店做过指定预算范围的策划师List
     *
     * @return
     */
    public static List<String> getHadDoPlannerList(String hotelId, String hotelName, String amountInterval, List<String> distanceCandoPlannerList) {
        List<String> list = new ArrayList<>();
        ResultScanner scanner = HBaseUtil.getScanner("tb_worker_wedding_order");
        for (Result result : scanner) {
            String worker_id = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("worker_id")));
            String wedding_id = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("wedding_id")));
            // 1.查询是否为策划师
//            String planner_type = getWorkerFlag(worker_id);
//            if (planner_type.equals("0")) {
            // 2.根据wedding_id查询酒店和预算是否满足约束
            if (distanceCandoPlannerList.contains(worker_id)) {
                if (getWeddingInfo2getIsLegal(wedding_id, hotelId, hotelName, amountInterval) == true && !list.contains(worker_id)) {
                    list.add(worker_id);
                }
            }
//            }
        }
        return list;
    }

    /**
     * 根据职业人id，查询其类型
     *
     * @param worker_id
     * @return
     */
    public static String getWorkerFlag(String worker_id) {
        String planner_type = "-1";
        try {
            String start = worker_id + ":::1";
            String stop = worker_id + ":::2";
            ResultScanner scanner = HBaseUtil.queryRowsWithKeys("worker_service_info", start, stop);
            for (Result result : scanner) {
                String flag = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("flag")));
                if (flag != null) {
                    planner_type = flag;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return planner_type;
    }

    /**
     * 判断是否为策划师
     *
     * @param worker_id
     * @return
     */
    public static boolean workerIsPlanner(String worker_id) {
        String flag = HBaseUtil.getValue("worker_service_info", worker_id + ":::1", "info", "flag");
        if (flag.equals("0")) {
            return true;
        }
        return false;
    }

    /**
     * 通过获取婚礼信息，判断是否合法（合法判断，酒店id对应，预算范围对应）
     *
     * @param wedding_id
     * @return
     */
    public static boolean getWeddingInfo2getIsLegal(String wedding_id, String hotelId, String hotelName, String amountInterval) {
        try {
            Result result = HBaseUtil.getRow("tb_user_wedding", wedding_id);
            String hotel_id = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("hotel_id")));
            String hotel = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("hotel")));
            String budget_min = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("budget_min")));
            String budget_max = Bytes.toString(result.getValue(Bytes.toBytes("info"), Bytes.toBytes("budget_max")));
            int weak_min = 0;
            int weak_max = 0;
            if (budget_min != null) {
                weak_min = Integer.parseInt(budget_min);
            }
            if (budget_max != null) {
                weak_max = Integer.parseInt(budget_max);
            }
            // 1.判断酒店对应。
            if (hotelId.equals(hotel_id) && hotelName.equals(hotel)) {
                // 2.判断预算对应。
                int max = -1;
                int min = -1;
                if (amountInterval.equals("1")) {
                    min = 0;
                    max = 12000;
                } else if (amountInterval.equals("2")) {
                    min = 12000;
                    max = 18000;
                } else if (amountInterval.equals("3")) {
                    min = 18000;
                    max = 25000;
                } else if (amountInterval.equals("4")) {
                    min = 25000;
                    max = 34000;
                } else if (amountInterval.equals("5")) {
                    min = 34000;
                    max = 50000;
                }
                if ((weak_min >= min && weak_min <= max) && (weak_max >= min && weak_max <= max)) {
                    return true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 根据酒店id，获取省市区信息
     *
     * @param hotelId
     * @return
     */
    public static String[] getHotelInfo(String hotelId) {
        String[] arr = new String[3];
        try {
            Result res = HBaseUtil.getRow("tb_hotel", hotelId);
            String province = Bytes.toString(res.getValue(Bytes.toBytes("info"), Bytes.toBytes("province")));
            String city = Bytes.toString(res.getValue(Bytes.toBytes("info"), Bytes.toBytes("city")));
            String zone = Bytes.toString(res.getValue(Bytes.toBytes("info"), Bytes.toBytes("zone")));
            arr[0] = (province == null) ? "" : province;
            arr[1] = (city == null) ? "" : city;
            arr[2] = (zone == null) ? "" : zone;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return arr;
    }

    /**
     * 存储推荐结果到HBase。
     * by hiwes.
     *
     * @param wedding_id
     * @param planner_id
     */
    public static void saveRecomResult2HBase(String wedding_id, String planner_id, String inArea) {
        try {
            String hotel_id = HBaseUtil.getValue("v2_rp_tb_user_wedding", wedding_id, "info", "hotel_id");
            String today = MyUtils.getFromToday(0);
            String start = today + "=" + wedding_id + "=" + inArea + "=0"; // 按天存储推荐数据
            String stop = today + "=" + wedding_id + "=" + inArea + "=99999"; // 2019.12.17之前，没有第三个字段iArea。
            ResultScanner result = HBaseUtil.queryRowsWithKeys("recom_planner_result", start, stop);
            int len = 1;
            for (Result res : result) {
                len++;
            }
            String rowkey = today + "=" + wedding_id + "=" + inArea + "=" + String.valueOf(len);
            Put put = new Put(Bytes.toBytes(rowkey));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("wedding_id"), Bytes.toBytes(wedding_id));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("hotel_id"), Bytes.toBytes(hotel_id));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("planner_id"), Bytes.toBytes(planner_id));
            put.addColumn(Bytes.toBytes("info"), Bytes.toBytes("inArea"), Bytes.toBytes(inArea));
            List<Put> list = new ArrayList<Put>();
            list.add(put);
            HBaseUtil.put("recom_planner_result", list);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

//    public static WorkerVO getWorkerVO(Result r) {
//        WorkerVO vo = new WorkerVO();
//        String id = Bytes.toString(r.getRow());
//        String name = stringCol(r, "name")));
//        String realName = stringCol(r, "real_name")));
//        String avator = stringCol(r, "avator")));
//        //    String vocation; //rp_tb_user_wedding_team_member----按worker_id批量查询后的vocation————暂时用不到。
//        String vocationId = stringCol(r, "vocation_id")));
//        String homePage = stringCol(r, "home_page")));
//        int sort = 0;   //rp_tb_vocation----sort
//        String userId = stringCol(r, "user_id")));
//        int height = Integer.parseInt(stringCol(r, "height"));
//        int weight = Integer.parseInt(stringCol(r, "weight"));
//        int sex = Integer.parseInt(stringCol(r, "sex"));
//        String birthday = stringCol(r, "birthday")));
//        String profile = stringCol(r, "profile")));
//        int dailyLimit = Integer.parseInt(stringCol(r, "daily_limit"));
//        String status = stringCol(r, "status")));
//        Result location = HBaseUtil.getRow("rp_tb_worker_location", Bytes.toBytes(workerId));
//        String cityId = Bytes.toString(location.getValue(Bytes.toBytes("info"), Bytes.toBytes("city_id")));
//        String provinceId = Bytes.toString(location.getValue(Bytes.toBytes("info"), Bytes.toBytes("province_id")));
//        String cityName = Bytes.toString(location.getValue(Bytes.toBytes("info"), Bytes.toBytes("city_name")));
//        String provinceName = Bytes.toString(location.getValue(Bytes.toBytes("info"), Bytes.toBytes("province_name")));
//        List<WorkerServiceCityVO> serviceCity = new ArrayList<>();
//        ResultScanner city = HBaseUtil.queryRowsWithKeys("rp_tb_worker_service_city", id + ":0", id + ":999");
//        for (Result res : city) {
//            String in_id = Bytes.toString(res.getValue(Bytes.toBytes("info"), Bytes.toBytes("id")));
//            String in_cityId = Bytes.toString(res.getValue(Bytes.toBytes("info"), Bytes.toBytes("city_id")));
//            String in_provinceId = Bytes.toString(res.getValue(Bytes.toBytes("info"), Bytes.toBytes("province_id")));
//            String in_cityName = Bytes.toString(res.getValue(Bytes.toBytes("info"), Bytes.toBytes("city_name")));
//            String in_provinceName = Bytes.toString(res.getValue(Bytes.toBytes("info"), Bytes.toBytes("province_name")));
//            WorkerServiceCityVO vvo = new WorkerServiceCityVO(in_id, id, in_cityId, in_provinceId, in_cityName, in_provinceName);
//            serviceCity.add(vvo);
//        }
//        Date ctime = null;
//        try {
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            ctime = sdf.parse(stringCol(r, "ctime"));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        int dailyType = 0;      //找不到
//        String addressId = Bytes.toString(location.getValue(Bytes.toBytes("info"), Bytes.toBytes("address_id")));
//        String addressName = Bytes.toString(location.getValue(Bytes.toBytes("info"), Bytes.toBytes("address_name")));
//        vo = new WorkerVO(id, name, realName, avator, vocationId, homePage, sort, userId, height, weight, sex, birthday, profile, dailyLimit, status, cityId, provinceId, cityName, provinceName, serviceCity, ctime, dailyType, addressId, addressName);
//
//        return vo;
//    }


}
